<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>数据代理的定义</title>
    <!--引入Vue-->
    <script type="text/javascript" src="./js/vue.js"></script>
</head>

<body>
    <!--数据代理，通过一个对象代理对另一个对象中属性的操作（读、取）-->

    <script>
        let obj = {
            x: 100
        }
        let obj2 = {
                y: 200

            }
            // Object.defineProperty() 给obj2也定义一个x,
        Object.defineProperty(obj2, 'x', {
            //当有人要读取xobj2的x时触发 get() ，obj的x也被也是
            get() {
                return obj.x
            },
            //当有人要修改xobj2的x时触发 set() ,obj的x也被修改 
            set(value) {
                obj.x = value
            }
        })

        console.log(obj2)
    </script>









</body>

</html>